package com.andnnl.reduce;

import java.util.Arrays;
import java.util.Comparator;
import java.util.function.BinaryOperator;

/**
 * Created by chenss on 2020/12/9.
 */
public class ReduceTest {
    public static void main(String[] args) {
        //取最短长度的字符串
        String[] aa=new String[]{"asdf 234","asdf","asdf1","asdf 12","asdf 34123"};
        Arrays.stream(aa).reduce((i, j) -> i.length() > j.length()?j:i).ifPresent(System.out::println);

        Arrays.stream(aa).reduce(BinaryOperator.minBy(Comparator.comparing(String::length))).ifPresent(System.out::println);

        Arrays.stream(aa).map(a->a.length()).forEach(System.out::println);
    }
}
